package com.mcc.myapplication

fun whenDemo1(x: Int) {
    when (x) {
        1 -> print("x == 1")
        2 -> print("x == 2")
        else -> {
            print("x=$x is neither 1 nor 2")
        }
    }
    println()
}

enum class Bit {
    ZERO, ONE, TWO
}

fun getRandomBit(): Bit {
    return Bit.ZERO
}

fun whenDemo2() {
    val numericValue = when (getRandomBit()) {
        Bit.ZERO -> 0
        Bit.ONE -> 1
        Bit.TWO -> 2
        // 'else' is not required because all cases are covered
    }
    println(numericValue)
}

fun whenDemo3(x: Int, s: String) {
    when (x) {
        0, 1 -> print("x == 0 or x == 1")
        else -> print("otherwise")
    }

    when (x) {
        s.toInt() -> print("s encodes x")
        else -> print("s does not encode x")
    }

    val validNumbers = listOf(3, 4, 5)
    when (x) {
        in 1..10 -> print("x is in the range")
        in validNumbers -> print("x is valid")
        !in 10..20 -> print("x is outside the range")
        else -> print("none of the above")
    }
}


fun main() {
    whenDemo1(3)
    whenDemo2()
}